﻿<Page
    x:Class="Ch9RSS_Universal.HubPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Ch9RSS_Universal"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:convert="using:Ch9RSS_Universal.Converters"
    xmlns:data="using:Ch9RSS_Universal.Data"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    mc:Ignorable="d"
    RequestedTheme="Light">

    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Default">
                    <ImageBrush x:Key="HubBackgroundImageBrush" ImageSource="Assets/HubBackground.png"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrast">
                    <ImageBrush x:Key="HubBackgroundImageBrush" ImageSource="{x:Null}"/>
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>

            <convert:ListLimitConverter x:Key="ListLimitConvert" />
            <!-- Need to do a query on the pixel space available, change the 
                  FeaturedLimit accordingly 
                Pseudocode implementation:
                dpw = GetDevicePixelWidth
                dph = GetDevicePizelHeight
                itemsAcross = (dpw*2) / 340;
                itemsDown = (dph - 200) /191;
                featuredLimit = itemsAcross * itemsDown;
            
            -->
            <x:Int32 x:Key="FeaturedLimit">6</x:Int32>
            <convert:ThumbConverter x:Key="ThumbConverter" />
            <x:Double x:Key="featureTargetHeight">191</x:Double>
            <x:Double x:Key="featureTargetWidth">340</x:Double>
            <x:Double x:Key="standardTargetHeight">125</x:Double>
            <x:Double x:Key="standardTargetWidth">222</x:Double>


            <DataTemplate x:Key="FeaturedItemsTemplate">
                <Grid Margin="5,10,5,10" Height="{StaticResource featureTargetHeight}"
                  Width="{StaticResource featureTargetWidth}">
                    <Border x:Name="parentBorder" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" >
                        <Image Source="{Binding thumbnail, Converter={StaticResource ThumbConverter}, ConverterParameter={StaticResource featureTargetHeight}}" 
                                   Stretch="UniformToFill" 
                                   />
                    </Border>
                    <StackPanel VerticalAlignment="Bottom" Margin="0,0,0,0" Background="#CCF97600">
                        <TextBlock Text="{Binding title}" Foreground="White" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="2" Margin="10,5,5,10" FontSize="16" />
                    </StackPanel>
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="StandardItemsTemplate">
                <Grid Margin="10,10,20,10"  
                 >
                    <!-- 
                  Height="{StaticResource standardTargetHeight}"
                  Width="{StaticResource standardTargetWidth}" -->
                    <Border x:Name="parentBorder" 
                            Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
                            BorderThickness="2" BorderBrush="#FF2C2C2C">
                        <Image Source="{Binding thumbnail, Converter={StaticResource ThumbConverter}, ConverterParameter={StaticResource standardTargetHeight}}" 
                                   Stretch="UniformToFill" 
                                   />
                    </Border>
                    <!--StackPanel VerticalAlignment="Bottom" Margin="0,0,0,0" Background="#CCF97600">
                    <TextBlock Text="{Binding title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="3" Margin="5,5,5,10" FontSize="16" />
                </-->
                </Grid>
            </DataTemplate>

            <!--<DataTemplate x:Key="RecentItemsTemplate">
                <Grid Margin="10,10,20,10"  
                      Height="{StaticResource standardTargetHeight}"
                 >
                    <Border x:Name="parentBorder" 
                            Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
                            BorderThickness="2" BorderBrush="#FF2C2C2C">
                        <Image Source="{Binding thumbnail, Converter={StaticResource ThumbConverter}, ConverterParameter={StaticResource standardTargetHeight}}" 
                                   Stretch="UniformToFill" 
                                   />
                    </Border>
                    <StackPanel VerticalAlignment="Bottom" Margin="0,0,0,0" Background="#CCF97600">
                        <TextBlock Text="{Binding LatestViewTime}" Foreground="White" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="2" Margin="10,5,5,10" FontSize="16" />
                    </StackPanel>
                </Grid>
            </DataTemplate>-->

            <DataTemplate x:Key="RecentItemsTemplate">
                <Grid Margin="5,10,5,10" Height="200">
                    <Border x:Name="parentBorder" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" >
                        <Image Source="{Binding thumbnail, Converter={StaticResource ThumbConverter}, ConverterParameter={StaticResource featureTargetHeight}}" 
                                   Stretch="UniformToFill" 
                                   />
                    </Border>
                    <StackPanel VerticalAlignment="Bottom" Orientation="Horizontal" Margin="0,0,0,0" 
                            Background="#CCF97600" 
                            >
                        <TextBlock Text="Left off at: " Foreground="White" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="2" Margin="5,5,5,5" FontSize="16" />
                        <TextBlock Text="{Binding LatestViewTime}" Foreground="White" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" MaxLines="2" Margin="5,5,5,5" FontSize="16" />
                    </StackPanel>
                </Grid>
            </DataTemplate>


            <DataTemplate x:Key="HubSectionHeaderTemplate">
                <Grid>
                    <TextBlock Text="{Binding}" 
                           Margin="16,0,0,0"
                           Style="{StaticResource SubheaderTextBlockStyle}" />
                </Grid>
            </DataTemplate>
            
        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="LayoutRoot" 
          Margin="0,0,0,0" 
          Background="White"
          Loaded="LayoutRoot_Loaded">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Height="50" VerticalAlignment="Top" Background="{StaticResource Ch9Orange}"  >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Border >                
                <Image Margin="10,5,0,5" HorizontalAlignment="Left" Source="ms-appx:///Assets/Ch9Logo.png" />
            </Border>
            <TextBlock Grid.Column="1" Style="{StaticResource GroupHeaderTextBlockStyle}" 
                       Text="Channel 9 Viewer" 
                       Foreground="White"
                       VerticalAlignment="Center"
                       Margin="10,0,0,0" FontSize="36" FontFamily="Global User Interface"/>
        </Grid>
        <Hub Grid.Row="1" Margin="0,25,0,0">
            <HubSection 
                        Header="Featured" 
                        HeaderTemplate="{StaticResource HubSectionHeaderTemplate}" 
                        Width="760"                        
                        >
                <DataTemplate>
                    <Grid>
                        <GridView x:Uid="FeaturedGridView" 
                                  ItemsSource="{Binding LimitFeaturedItems}"
                                  SelectionChanged="FeaturedItem_Changed"
                                  ItemTemplate="{StaticResource FeaturedItemsTemplate}"
                                  >
                        </GridView>
                    </Grid>
                </DataTemplate>
            </HubSection>
            <HubSection Header="Shows" HeaderTemplate="{StaticResource HubSectionHeaderTemplate}" >
                <DataTemplate>
                    <GridView
                        x:Uid="ShowsGridView"
                        ItemsSource="{Binding ShowItems}"
                        SelectionChanged="ShowItem_Changed"
                        ItemTemplate="{StaticResource StandardItemsTemplate}">
                    </GridView>
                </DataTemplate>
            </HubSection>
            <HubSection Header="Series" HeaderTemplate="{StaticResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <Grid>
                        <GridView x:Uid="SeriesGridView" 
                                  ItemsSource="{Binding SeriesItems}"
                                  SelectionChanged="SeriesItem_Changed"
                                  ItemTemplate="{StaticResource StandardItemsTemplate}"
                                  >

                        </GridView>
                    </Grid>
                </DataTemplate>
            </HubSection>
            <HubSection Header="Recent" HeaderTemplate="{StaticResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <Grid>
                        <ListView 
                                ItemsSource="{Binding RecentlyViewed}"
                                SelectionChanged="FeaturedItem_Changed"
                                ItemTemplate="{StaticResource RecentItemsTemplate}"
                                  >

                        </ListView>
                    </Grid>
                </DataTemplate>
            </HubSection>
        </Hub>
        <!--<Hub x:Name="Hub" x:Uid="Hub" Header="application name" Background="{ThemeResource HubBackgroundImageBrush}">
            <HubSection x:Uid="HubSection1" Header="SECTION 1" DataContext="{Binding Groups}">
                <DataTemplate>
                    <ListView
                        ItemsSource="{Binding}"
                        IsItemClickEnabled="True"
                        ItemClick="GroupSection_ItemClick"
                        ContinuumNavigationTransitionInfo.ExitElementContainer="True">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding Title}" Style="{ThemeResource ListViewItemTextBlockStyle}" />
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </DataTemplate>
            </HubSection>

            <HubSection x:Uid="HubSection2" Header="SECTION 2" Width="Auto"
                         DataContext="{Binding Groups[0]}">
                <DataTemplate>
                    <GridView
                        ItemsSource="{Binding Items}"
                        AutomationProperties.AutomationId="ItemGridView"
                        AutomationProperties.Name="Items In Group"
                        ItemTemplate="{StaticResource Standard200x180TileItemTemplate}"
                        SelectionMode="None"
                        IsItemClickEnabled="True"
                        ItemClick="ItemView_ItemClick"
                        ContinuumNavigationTransitionInfo.ExitElementContainer="True">
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsWrapGrid />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                    </GridView>
                </DataTemplate>
            </HubSection>

            <HubSection x:Uid="HubSection3" Header="SECTION 3"
                        DataContext="{Binding Groups[1]}">
                <DataTemplate>
                    <ListView 
                        AutomationProperties.AutomationId="ItemListViewSection3"
                        AutomationProperties.Name="Items In Group"
                        SelectionMode="None"
                        IsItemClickEnabled="True"
                        ItemsSource="{Binding Items}"
                        ItemTemplate="{StaticResource StandardTripleLineItemTemplate}"
                        ItemClick="ItemView_ItemClick"
                        ContinuumNavigationTransitionInfo.ExitElementContainer="True">
                    </ListView>
                </DataTemplate>
            </HubSection>

            <HubSection x:Uid="HubSection4" Header="SECTION 4"
                        DataContext="{Binding Groups[2]}">
                <DataTemplate>
                    <ListView 
                        AutomationProperties.AutomationId="ItemListViewSection4"
                        AutomationProperties.Name="Items In Group"
                        SelectionMode="None"
                        IsItemClickEnabled="True"
                        ItemsSource="{Binding Items}"
                        ItemClick="ItemView_ItemClick"
                        ContinuumNavigationTransitionInfo.ExitElementContainer="True">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding Title}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                                    <TextBlock Text="{Binding Subtitle}" Style="{ThemeResource ListViewItemContentTextBlockStyle}"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </DataTemplate>
            </HubSection>

            <HubSection x:Uid="HubSection5" Header="SECTION 5"
                        DataContext="{Binding Groups[3]}">
                <DataTemplate>
                    <ListView 
                        AutomationProperties.AutomationId="ItemListViewSection5"
                        AutomationProperties.Name="Items In Group"
                        SelectionMode="None"
                        IsItemClickEnabled="True"
                        ItemsSource="{Binding Items}"
                        ItemTemplate="{StaticResource StandardDoubleLineItemTemplate}"
                        ItemClick="ItemView_ItemClick"
                        ContinuumNavigationTransitionInfo.ExitElementContainer="True">
                    </ListView>
                </DataTemplate>
            </HubSection>
        </Hub>-->
    </Grid>
</Page>